package com.sanyou.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sanyou.mapper.OperLogMapper;
import com.sanyou.pojo.OperLog;
import com.sanyou.pojo.vo.IndustryDataVo;
import com.sanyou.pojo.vo.OperLogVo;
import com.sanyou.service.OperLogService;
import com.sanyou.utils.PagedResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class OperLogServiceImpl implements OperLogService {
    @Autowired
    OperLogMapper operLogMapper;

    @Override
    public void insert(OperLog operLog) {
        operLogMapper.insert(operLog);
    }

    @Override
    public void insert(String productCode, int operType, int productState, String content, String operatorId) {
        OperLog operLog = OperLog.builder()
                .operType(operType)
                .productState(productState)
                .productCode(productCode)
                .content(content)
                .logDate(new Date())
                .operatorId(operatorId)
                .build();
        insert(operLog);
    }

    @Override
    public PagedResult queryByProductCode(String productCode,Integer page, Integer pageSize) {
        Page<OperLogVo> list = PageHelper.startPage(page, pageSize)
                .doSelectPage(() -> operLogMapper.queryByProductCode(productCode));
        PagedResult pagedResult = new PagedResult();
        pagedResult.setPage(list.getPageNum());
        pagedResult.setTotal(list.getPages());
        pagedResult.setRecords(list.getTotal());
        pagedResult.setRows(list.getResult());
        return pagedResult;
    }
}
